package com.kzj.mls.recyclerCard.cardView;

import android.content.Context;
import android.content.Intent;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.kzj.mls.R;
import com.kzj.mls.activity.OrderDetailsActivity;
import com.kzj.mls.activity.OrderWebActivity;
import com.kzj.mls.beans.OrderBean;
import com.kzj.mls.global.App;
import com.kzj.mls.recyclerCard.basic.CardItemView;
import com.kzj.mls.recyclerCard.card.other.OrderCard;
import com.kzj.mls.util.ImageUtil;

/**
 * Created by xyg on 2015/10/26.
 */
public class OrderCardView extends CardItemView<OrderCard> {
    private OrderBean orderBean;
    private Context context;
    private TextView textView_type;
    private TextView textView_status;
    private ImageView imageView_logo;
    private TextView textView_goods_name;
    private TextView textView_goods_amount;
    private TextView textView_order_amount;
    private TextView textView_time;
    private TextView textView_address;
    private TextView textView_phone;
    private TextView textView_remarks;
    private TextView textView_call;
    private TextView textView_complete;
    private TextView textView_sure;
    private static final String STORE = "2";
    private static final String ADDRESS = "1";
    private static final String SERVICE = "30";//待服务
    private static final String CONFIRM = "25";//待确认
    private static final String CANCEL = "0";//已取消
    private static final String COMPLETE = "40";//已完成
    private static final String Evaluation = "1";//有评价
    private static final String Not_Evaluation = "0";//无评价

    public OrderCardView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public OrderCardView(Context context) {
        super(context);
        this.context = context;
    }

    public OrderCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    @Override
    public void build(final OrderCard card) {
        super.build(card);
        orderBean = card.getOrderBean();
        textView_type = (TextView) findViewById(R.id.textView_type);
        textView_status = (TextView) findViewById(R.id.textView_status);
        imageView_logo = (ImageView) findViewById(R.id.imageView_logo);
        textView_goods_name = (TextView) findViewById(R.id.textView_goods_name);
        textView_goods_amount = (TextView) findViewById(R.id.textView_goods_amount);
        textView_order_amount = (TextView) findViewById(R.id.textView_order_amount);
        textView_time = (TextView) findViewById(R.id.textView_time);
        textView_address = (TextView) findViewById(R.id.textView_address);
        textView_phone = (TextView) findViewById(R.id.textView_phone);
        textView_remarks = (TextView) findViewById(R.id.textView_remarks);
        textView_call = (TextView) findViewById(R.id.textView_call);
        textView_complete = (TextView) findViewById(R.id.textView_complete);
        textView_sure = (TextView) findViewById(R.id.textView_sure);

        textView_remarks.setVisibility(GONE);
        textView_call.setVisibility(GONE);
        textView_sure.setVisibility(GONE);
        textView_complete.setVisibility(GONE);


        App.displayImageHttpOrFile(orderBean.getGoods_image(), imageView_logo, ImageUtil.OptionsNormal());
        textView_status.setText(orderBean.getOrder_status());
        textView_goods_amount.setText(orderBean.getGoods_amount());
        textView_goods_name.setText(orderBean.getGoods_name());
        textView_order_amount.setText(orderBean.getOrder_amount());
        textView_type.setText(orderBean.getSite_type_lang() + "：" + orderBean.getOrder_sn());
        textView_time.setText("预约时间：" + orderBean.getMake_time());
        if (orderBean.getSite_type().equals(STORE)) {
            textView_address.setText("服务门店：" + orderBean.getAddress());
        } else {
            textView_address.setText("服务地址：" + orderBean.getAddress());
        }
        textView_phone.setText("客户电话：" + orderBean.getPhone_mob());
        if (orderBean.getPostscript() != null && !orderBean.getPostscript().equals("")) {
            textView_remarks.setVisibility(VISIBLE);
            textView_remarks.setText("备注：" + orderBean.getPostscript());
        } else {
            textView_remarks.setVisibility(GONE);
        }
        String status = orderBean.getStatus();
        switch (status) {
            case SERVICE:
                textView_call.setVisibility(VISIBLE);
                textView_complete.setVisibility(VISIBLE);
                break;
            case CONFIRM:
                textView_call.setVisibility(VISIBLE);
                textView_sure.setVisibility(VISIBLE);
                break;
            case COMPLETE:
                textView_call.setVisibility(VISIBLE);
                break;
            case CANCEL:
                textView_call.setVisibility(VISIBLE);
                break;
        }
        textView_call.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                card.getOnNormalButtonPressedListener().onButtonPressedListener(v, card);
            }
        });
        textView_sure.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                card.getOnNormalButtonPressedListener().onButtonPressedListener(v, card);
            }
        });
        textView_complete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                card.getOnNormalButtonPressedListener().onButtonPressedListener(v, card);
            }
        });


        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, OrderDetailsActivity.class);

                intent.putExtra("order_id", card.getOrderBean().getOrder_id());
                context.startActivity(intent);
            }
        });
    }
}
